package cn.itsource.pethome.order.controller;

import cn.itsource.pethome.Basic.util.AjaxResult;
import cn.itsource.pethome.Basic.util.UserContext;
import cn.itsource.pethome.order.service.IProductOrderService;
import cn.itsource.pethome.user.domain.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import redis.clients.jedis.params.Params;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

@RestController
@RequestMapping("/productOrder")
public class ProductOrderController {
    @Autowired
    private IProductOrderService productOrderService;
    @PostMapping("/submitOrder")
    public AjaxResult submitOrder(@RequestBody Map<String,Object> param, HttpServletRequest request){
        try {
            //获取下单用户
            User loginUser = UserContext.getLoginUser(request);
            String formhtml = productOrderService.submitOrder(param, loginUser);
            return new AjaxResult().setResult(formhtml);
        } catch (Exception e) {
            e.printStackTrace();
            return new AjaxResult(false,e.getMessage());
        }
    }
}
